package cn.cdeden.resource.controller;

import java.util.List;

import cn.cdeden.resource.domain.bo.SysOssBarrelBo;
import cn.cdeden.resource.domain.vo.SysOssBarrelVo;
import cn.cdeden.resource.service.ISysOssBarrelService;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import cn.cdeden.common.idempotent.annotation.RepeatSubmit;
import cn.cdeden.common.log.annotation.Log;
import cn.cdeden.common.web.core.BaseController;
import cn.cdeden.common.mybatis.core.page.PageQuery;
import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.validate.AddGroup;
import cn.cdeden.common.core.validate.EditGroup;
import cn.cdeden.common.log.enums.BusinessType;
import cn.cdeden.common.excel.utils.ExcelUtil;
import cn.cdeden.common.core.utils.page.TableDataInfo;

/**
 * 对象存储桶配置配置
 * 前端访问路由地址为:/system/ossBarrel
 *
 * @author Yu.
 * @date 2024-12-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("enterprisePermServiceBarrel")
public class SysOssBarrelController extends BaseController {

    private final ISysOssBarrelService sysOssBarrelService;

    /**
     * 查询对象存储桶配置配置列表
     */
    @SaCheckPermission("system:ossBarrel:list")
    @GetMapping("/list")
    public TableDataInfo<SysOssBarrelVo> list(SysOssBarrelBo bo, PageQuery pageQuery) {
        return sysOssBarrelService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出对象存储桶配置配置列表
     */
    @SaCheckPermission("system:ossBarrel:export")
    @Log(title = "对象存储桶配置配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOssBarrelBo bo, HttpServletResponse response) {
        List<SysOssBarrelVo> list = sysOssBarrelService.queryList(bo);
        ExcelUtil.exportExcel(list, "对象存储桶配置配置", SysOssBarrelVo.class, response);
    }

    /**
     * 获取对象存储桶配置配置详细信息
     *
     * @param ossBarrelId 主键
     */
    @SaCheckPermission("system:ossBarrel:query")
    @GetMapping("/{ossBarrelId}")
    public R<SysOssBarrelVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ossBarrelId) {
        return R.ok(sysOssBarrelService.queryById(ossBarrelId));
    }

    /**
     * 新增对象存储桶配置配置
     */
    @SaCheckPermission("system:ossBarrel:add")
    @Log(title = "对象存储桶配置配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOssBarrelBo bo) {
        return toAjax(sysOssBarrelService.insertByBo(bo));
    }

    /**
     * 修改对象存储桶配置配置
     */
    @SaCheckPermission("system:ossBarrel:edit")
    @Log(title = "对象存储桶配置配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOssBarrelBo bo) {
        return toAjax(sysOssBarrelService.updateByBo(bo));
    }

    /**
     * 删除对象存储桶配置配置
     *
     * @param ossBarrelIds 主键串
     */
    @SaCheckPermission("system:ossBarrel:remove")
    @Log(title = "对象存储桶配置配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ossBarrelIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ossBarrelIds) {
        return toAjax(sysOssBarrelService.deleteWithValidByIds(List.of(ossBarrelIds), true));
    }
}
